import { createRouter, createWebHistory } from "vue-router";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "/login",
    },
    {
      path: "/home",
      component: () => import("@/pages/home/Index.vue"),
      children: [
        {
          path: "/home",
          redirect: "/home/welcome",
        },
        {
          path: "/home/welcome",
          component: () => import("@/pages/home/welcome/Index.vue"),
          meta: {
            mbxarr: ["xxx"],
          },
        },
        {
          path: "/home/bannerlist",
          component: () => import("@/pages/home/bannerList/Index.vue"),
        },
        {
          path: "/home/banneradd",
          component: () => import("@/pages/home/bannerAdd/Index.vue"),
        },
        {
          path: "/home/pro",
          component: () => import("@/pages/home/pro/Index.vue"),
        },
        {
          path: "/home/user",
          component: () => import("@/pages/home/user/Index.vue"),
        },
        {
          path: "/home/admin",
          component: () => import("@/pages/home/admin/Index.vue"),
        },
        {
          path: "/home/echarts",
          component: () => import("@/pages/home/echarts/Index.vue"),
        },
        {
          path: "/home/rich",
          component: () => import("@/pages/home/rich/Index.vue"),
        },
        {
          path: "/home/md",
          component: () => import("@/pages/home/md/Index.vue"),
        },
        {
          path: "/home/export",
          component: () => import("@/pages/home/export/Index.vue"),
        },
        {
          path: "/home/import",
          component: () => import("@/pages/home/import/Index.vue"),
        },
        {
          path: "/home/map",
          component: () => import("@/pages/home/map/Index.vue"),
        },
      ],
      beforeEnter(to, from, next) {
        if (sessionStorage.getItem("token")) {
          next();
        } else {
          next("/login");
        }
      },
    },
    {
      path: "/login",
      component: () => import("@/pages/login/Index.vue"),
    },
    {
      path: "/:pathMatch(.*)*",
      component: () => import("@/pages/notFound/Index.vue"),
    },
  ],
});

export default router;
